home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnumake / pdmake.zoo / check.c < prev    next >
C/C++ Source or Header  |  1991-09-25  |  3KB  |  134 lines

  1.     /***************************************************************\
  2.     *                                *
  3.     *  PDMAKE, Atari ST version                    *
  4.     *                                *
  5.     *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6.     *                                *
  7.     *  This port makes extensive use of the original net.sources    *
  8.     *  port by Jwahar Bammi.                    *
  9.     *                                *
  10.     *      Ton van Overbeek                        *
  11.     *      Email: TPC862@ESTEC.BITNET                *
  12.     *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13.     *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14.     *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15.     *             71450,3537  (CompuServe)                *
  16.     *                                *
  17.     \***************************************************************/
  18.  
  19. /*
  20.  *    Check structures for make.
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include "h.h"
  25.  
  26.  
  27. /*
  28.  *    Prints out the structures as defined in memory.  Good for check
  29.  *    that you make file does what you want (and for debugging make).
  30.  */
  31. void
  32. prt()
  33. {
  34.     register struct name *    np;
  35.     register struct depend *    dp;
  36.     register struct line *    lp;
  37.     register struct cmd *    cp;
  38.     register struct macro *    mp;
  39.  
  40.  
  41.     for (mp = macrohead; mp; mp = mp->m_next)
  42.         fprintf(stderr, "%s = %s\n", mp->m_name, mp->m_val);
  43.  
  44.     fputc('\n', stderr);
  45.  
  46.     for (np = namehead.n_next; np; np = np->n_next)
  47.     {
  48.         if (np->n_flag & N_DOUBLE)
  49.             fprintf(stderr, "%s::\n", np->n_name);
  50.         else
  51.             fprintf(stderr, "%s:\n", np->n_name);
  52.         if (np == firstname)
  53.             fprintf(stderr, "(MAIN NAME)\n");
  54.         for (lp = np->n_line; lp; lp = lp->l_next)
  55.         {
  56.             fputc(':', stderr);
  57.             for (dp = lp->l_dep; dp; dp = dp->d_next)
  58.                 fprintf(stderr, " %s", dp->d_name->n_name);
  59.             fputc('\n', stderr);
  60.  
  61.             for (cp = lp->l_cmd; cp; cp = cp->c_next)
  62. #ifdef os9
  63.                 fprintf(stderr, "-   %s\n", cp->c_cmd);
  64. #else
  65.                 fprintf(stderr, "-\t%s\n", cp->c_cmd);
  66. #endif
  67.             fputc('\n', stderr);
  68.         }
  69.         fputc('\n', stderr);
  70.     }
  71. }
  72.  
  73.  
  74. /*
  75.  *    Recursive routine that does the actual checking.
  76.  */
  77. void
  78. check(np)
  79. struct name *    np;
  80. {
  81.     register struct depend *    dp;
  82.     register struct line *    lp;
  83.  
  84.  
  85.     if (np->n_flag & N_MARK)
  86.         fatal("Circular dependency from %s", np->n_name);
  87.  
  88.     np->n_flag |= N_MARK;
  89.  
  90.     for (lp = np->n_line; lp; lp = lp->l_next)
  91.         for (dp = lp->l_dep; dp; dp = dp->d_next)
  92.             check(dp->d_name);
  93.  
  94.     np->n_flag &= ~N_MARK;
  95. }
  96.  
  97.  
  98. /*
  99.  *    Look for circular dependencies.
  100.  *    i.e.
  101.  *        a: b
  102.  *        b: a
  103.  *    is a circular dependency.
  104.  */
  105. void
  106. circh()
  107. {
  108.     register struct name *    np;
  109.  
  110.  
  111.     for (np = namehead.n_next; np; np = np->n_next)
  112.         check(np);
  113. }
  114.  
  115.  
  116. /*
  117.  *    Check the target .PRECIOUS, and mark its dependents as precious
  118.  */
  119. void
  120. precious()
  121. {
  122.     register struct depend *    dp;
  123.     register struct line *    lp;
  124.     register struct name *    np;
  125.  
  126.  
  127.     if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
  128.         return;
  129.  
  130.     for (lp = np->n_line; lp; lp = lp->l_next)
  131.         for (dp = lp->l_dep; dp; dp = dp->d_next)
  132.             dp->d_name->n_flag |= N_PREC;
  133. }
  134.